package webshop.data;

/*
 * Populator.java
 * Created on 16. juni 2008, 13:39
 */

import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;



/**
 * JDBC demo main class.
 * @author even
 */
public class Populator {
    
    public Populator() {
        Properties props = new Properties();
        props.put("toplink.ddl-generation", "drop-and-create-tables");
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("webshop", props);
        
        //create the tables
        emf.createEntityManager().close();
        emf.close();
    }


    public void populate() {        
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("webshop");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        
        Person per1 = new Person("Simon", "Lømslandsvei", 41587670);
        em.persist(per1);
        
        Person per2 = new Person("Renathe Todal Tande", "Lømslandsvei", 9568264);
        em.persist(per2);

        Person per3 = new Person("Vegard", "Tveit", 22222222);
        em.persist(per3);

        Person per4 = new Person("Sindre", "Lund", 1111111);
        em.persist(per4);

        em.getTransaction().commit();
        em.close();
        emf.close();
    }
    
    
    public static void main(String[] args) {
        System.getProperties().list(System.out);
        Populator m = new Populator();
        m.populate();
    }
    
}
